﻿using System;
using System.Collections.Generic;
 using UnityEngine;
  
 using System.Text;

 
    public abstract class IWeapon
    {  
    /// <summary>
    /// 攻击力
    /// </summary>
         protected int mAtk;

        public int atk {
            get { return mAtk; }
        }

        /// <summary>
    /// 攻击范围
    /// </summary>
        protected float mAtkRange;

        public float atkRange {       get { return mAtkRange; }   }

        /// <summary>
    /// 暴击
    /// </summary>
       // protected int mAtkPlusValue;
    /// <summary>
    /// 武器游戏物体
    /// </summary>
        protected GameObject mGameObject;
    /// <summary>
      /// 武器拥有者
      /// </summary>
        protected ICharacter mCharacter;
    /// <summary>
       ///  
       /// </summary>
        protected ParticleSystem mPariticle;
    /// <summary>
    /// 射击路径
    /// </summary>
        protected LineRenderer mLine;
    /// <summary>
    /// 灯光效果
    /// </summary>
        protected Light mLight;
    /// <summary>
    /// 声音
    /// </summary>
        protected AudioSource mAudio;
    /// <summary>
    /// 特效显示时间
    /// </summary>
        protected float mEffectDisplayTime = 0;

        public void Update()
        {
           //特效计时
            if (mEffectDisplayTime>0)
            {
                mEffectDisplayTime -= Time.deltaTime;
                if (mEffectDisplayTime<=0)
                {
                    DisableEffect();
                }

            }

        }
        /// <summary>
        /// 计时结束结束特效
        /// </summary>
        private void DisableEffect()
        {
        mLine.enabled = false;
        mLight.enabled = false;
        }

        public void Fire(Vector3 targetPosition)
        {
        //显示枪口特效
        PlayMuzzleEffect();
        //显示子弹轨迹特效
        PlayBulletEffect(targetPosition);
        //设置特效显示时间
            SetEffectDisplayTime();
        //播放声音
        PlaySound();
        }
    /// <summary>
    /// 设置特效播放时间
    /// </summary>
        protected abstract void SetEffectDisplayTime();
    /// <summary>
    /// 播放枪口特效
    /// </summary>
        protected virtual void PlayMuzzleEffect()
        {
        mPariticle.Stop();
        mPariticle.Play();
        mLight.enabled = true;
    }

        /// <summary>
        /// 子弹轨迹
        /// </summary>
        /// <param name="targetPosition"></param>
        protected abstract void PlayBulletEffect(Vector3 targetPosition);

        protected virtual void DoPlayBulletEffect(float width, Vector3 targetPosition)
        {
        mLight.enabled = true;
        mLine.startWidth = width;
        mLine.endWidth = width;
        mLine.SetPosition(0, mGameObject.transform.position);
        mLine.SetPosition(1, targetPosition);
    }

        /// <summary>
        /// 播放声音
        /// </summary>
        protected abstract void PlaySound();
         
        protected void DoPlaySould(String soundName)
        {
        AudioClip clip = null; //todo 后面统一管理资源
        mAudio.clip = clip;
        mAudio.Play();
    }
    }
 
